package com.ly.designpatten.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Classname ProxyFactory
 * @Description TODO
 * @Date 2020/10/15 21:26
 * @Author 冷心影翼
 */
public class ProxyFactory<T> {

	interface A {
		int a = 0;
	}

	private T target;

	public ProxyFactory(T target) {
		this.target = target;
	}

	public T proxy() {
		return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), new InvocationHandler() {
			@Override
			public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
				System.out.println("Boss: ");
				Object invoke = method.invoke(target, args);
				return invoke;
			}
		});
	}

	public static void main(String[] args) {
		IBoss iBoss = new Boss();
		IBoss proxy = new ProxyFactory<>(iBoss).proxy();
		proxy.publish();


	}
}
